//
//  MyPhotoView.m
//  SmartRoadShow
//
//  Created by Tracy E on 10-9-26.
//  Copyright 2010 simonwang142232@gmail.com. All rights reserved.
//

#import "MyPhotoView.h"
#import <QuartzCore/QuartzCore.h>
#import "SendHttpRequest.h"
#import "MyDataSource.h"
#import "ArtTour.h"
#import "CallUtil.h"
#import "RS3ViewController.h"
#import "CacheManager.h"
#import "SmartRoadShowAppDelegate.h"
#import "MyTabBarController.h"
#import "MyNavigationController.h"
#import "PushedCitys.h"
#import "DetailWebViewController.h"
#import "OpenWaitView.h"
#import "Reachability.h"
#import "extev.h"
#import "Constants.h"

@interface MyPhotoView()
- (void)addJoinButton;
@end


@implementation MyPhotoView
@synthesize tag;
@synthesize rs3VC;
@synthesize city, time ,leftCityCount;




enum buttonState {
	red,
	gary,
};

- (id)initWithFrame:(CGRect)frame From:(NSInteger) from Stations:(NSMutableArray *)array CurrentStation:(NSInteger) index{
    if ((self = [super initWithFrame:frame])) {
				
		tag = index;
		
		stationArr = [array retain];

				
		self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.5];
		
		imageView = [[UIImageView alloc] init];
		imageView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
		
		[self addSubview:imageView];
		[imageView release];
		
    }
    return self;
}

- (void)locateAction{
	
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您将离开该应用前往地图服务，是否继续？"
													message:nil
												   delegate:self
										  cancelButtonTitle:@"确定"
										  otherButtonTitles:@"取消",nil];
	[alert setTag:666];
	[alert show];
	[alert release];
	
	
}


- (void)push{
	
	Reachability *internetReach = [Reachability reachabilityForInternetConnection];
	[internetReach startNotifier];	
	NetworkStatus netStatus = [internetReach currentReachabilityStatus];
	
	if (netStatus) {
		NSString* messageStr = (ifConcern == YES)? @"取消": @"加入";
		UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil
														message:[NSString stringWithFormat: @"您是否将该活动%@时间提醒?", messageStr]
													   delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
		alert.tag = 889;
		[alert show];
		[alert release];
		
	}	
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"本功能需要网络支持，请检查网络连接！"
													   delegate:nil cancelButtonTitle:@"确定"
											  otherButtonTitles:nil];
		[alert show];
		[alert release];		
	}
	

}


-(void)cancelAction{
	[rs3VC.segmentControl setUserInteractionEnabled:YES];
	[rs3VC.scrollView setScrollEnabled:YES];

	[appDelegate.tabBarController.tabBar setUserInteractionEnabled:YES];
	[rs3VC.navigationController.navigationBar setUserInteractionEnabled:YES];
	
	[joinView removeFromSuperview];
	
}



-(BOOL)textFieldShouldReturn:(UITextField *)textField{
	[textField resignFirstResponder];
	return YES;
}

- (void)setImage:(NSString *)imageURL{
	
	UIImage *image = [CacheManager getImageAccordingToURLString:imageURL];
	
	if (image != nil) {
		[imageView setImage:image];
		[self setBackgroundColor:[UIColor clearColor]];
		//--------
//		UIButton *join = [UIButton buttonWithType:UIButtonTypeCustom];
//		[join setTitle:@"我要参加" forState:UIControlStateNormal];
//		[join setTitle:@"我要参加" forState:UIControlStateHighlighted];
//		[join.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
//		[join setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//		[join setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
//		[join setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateHighlighted];
//		
//		[join setFrame:CGRectMake(34, 218, 90, 30)];
//		[join addTarget:self action:@selector(IWantJoin) forControlEvents:UIControlEventTouchUpInside];
//		join.layer.cornerRadius = 5;
//		join.layer.masksToBounds =	YES;
//		[self addSubview:join];
		//------------
		
		UIButton *moreInfo = [UIButton buttonWithType:UIButtonTypeCustom];
		[moreInfo setTitle:@"更多资讯" forState:UIControlStateNormal];
		[moreInfo setTitle:@"更多资讯" forState:UIControlStateHighlighted];
		[moreInfo.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
		[moreInfo setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		[moreInfo setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
		[moreInfo setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateHighlighted];
		
		[moreInfo setFrame:CGRectMake(134, 218, 90, 30)];
		[moreInfo addTarget:self action:@selector(getMoreInfo) forControlEvents:UIControlEventTouchUpInside];
		moreInfo.layer.cornerRadius = 5;
		moreInfo.layer.masksToBounds =	YES;
		[self addSubview:moreInfo];
		
		
		UIControl *control1 = [[UIControl alloc] initWithFrame:CGRectMake(190, 80, 60, 60)];
		[control1 addTarget:self action:@selector(locateAction) forControlEvents:UIControlEventTouchUpInside];
		[self addSubview:control1];
		[control1 release];
		
		UIButton *locate = [UIButton buttonWithType:UIButtonTypeCustom];
//		[locate setImage:[UIImage imageNamed:@"map.png"] forState:UIControlStateNormal];
		[locate setBackgroundImage:[UIImage imageNamed:@"map.png"] forState:UIControlStateNormal];
		[locate setFrame:CGRectMake(210, 95, 20, 20)];
		[locate addTarget:self action:@selector(locateAction) forControlEvents:UIControlEventTouchUpInside];
		[self addSubview:locate];


		[self addJoinButton];
		
	}
	else{
		downloadWait = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
		[downloadWait setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
		[downloadWait setCenter:imageView.center];
		[downloadWait startAnimating];
		[self addSubview:downloadWait];
		[downloadWait release];
		
		
		
		
		ImageDownloader* downLoader = [[[ImageDownloader alloc] init] autorelease];
		downLoader.imageReceiver = self;
		downLoader.imageURLString = imageURL;
		[downLoader startDownloadWithImageURLString:downLoader.imageURLString];
		
	}
}

- (void)addJoinButton{
	if (result) {
		UIButton *join = [UIButton buttonWithType:UIButtonTypeCustom];
		[join addTarget:self action:@selector(IWantJoin) forControlEvents:UIControlEventTouchUpInside];
		[join setTitle:@"我要参加" forState:UIControlStateNormal];
		[join.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
		[join setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		[join setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
		[join setFrame:CGRectMake(30, 220, 80, 30)];
		[self addSubview:join];
		
		
		UIControl *control2 = [[UIControl alloc] initWithFrame:CGRectMake(200, 5, 60, 80)];
		[control2 addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
		[self addSubview:control2];
		[control2 release];
		
		//没有关注过的，灰色
		if (![PushedCitys findById:newsId]) {
			ifConcern = NO;
			star = [UIButton buttonWithType:UIButtonTypeCustom];
			[star setFrame:CGRectMake(213,20,20,20)];
			[star setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
			buttonState = gary;
			[star addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
			[self addSubview:star];
		}
		//已经关注过的，红色
		else {
			ifConcern = YES;
			star = [UIButton buttonWithType:UIButtonTypeCustom];
			[star setFrame:CGRectMake(213,20,20,20)];
			[star setImage:[UIImage imageNamed:@"star_red.png"] forState:UIControlStateNormal];
			buttonState = red;
			[star addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
			[self addSubview:star];
		}
		
	}
	//过期的，灰色，不能点击
	else {
		star = [UIButton buttonWithType:UIButtonTypeCustom];
		[star setFrame:CGRectMake(213,20,20,20)];
		[star setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
		buttonState = gary;
		[self addSubview:star];
	}
}



-(void)imageDownloader:(ImageDownloader*)downloader didReceiveImage:(UIImage*)image{
	
	[imageView setImage:image];
	self.backgroundColor = [UIColor clearColor];
	
	[downloadWait stopAnimating];
	[downloadWait release];
	
	UIButton *moreInfo = [UIButton buttonWithType:UIButtonTypeCustom];
	[moreInfo setTitle:@"更多资讯" forState:UIControlStateNormal];
	[moreInfo setTitle:@"更多资讯" forState:UIControlStateHighlighted];
	[moreInfo.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
	[moreInfo setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	[moreInfo setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
	[moreInfo setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateHighlighted];
	
	[moreInfo setFrame:CGRectMake(150, 220, 80, 30)];
	[moreInfo addTarget:self action:@selector(getMoreInfo) forControlEvents:UIControlEventTouchUpInside];
	moreInfo.layer.cornerRadius = 5;
	moreInfo.layer.masksToBounds =	YES;
	[self addSubview:moreInfo];
	
	
	UIButton *locate = [UIButton buttonWithType:UIButtonTypeCustom];
	[locate setImage:[UIImage imageNamed:@"map.png"] forState:UIControlStateNormal];
	[locate setFrame:CGRectMake(210, 85, 20, 20)];
	[locate addTarget:self action:@selector(locateAction) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:locate];
	
	[self addJoinButton];
	
	[CacheManager setImage:image withImageURLString:downloader.imageURLString];

}

-(void)setPlaceLabelText:(NSString *)text{
}

-(void)setTimeLabelText:(NSString *)text{
	[timeLabel setText:text];
}

- (void)setPushID:(NSString *)_newsId City:(NSString *)City Time:(NSString *)Time{
	
	newsId = [_newsId retain];
	city = [City retain];
	time = [Time retain];
	
	NSString *stationTime = [[stationArr objectAtIndex:tag] _endtime];
	notiTime = [NSString stringWithFormat:@"%@",stationTime];
	
	NSCalendar* calendar = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
	
	NSDateComponents* comps = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
							   NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | 
							   NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
		
	NSString *year = [NSString stringWithFormat:@"%d",comps.year];
	NSString *month = nil;
	NSString *day = nil;
	
	
	if (comps.month < 10) {
		month = [NSString stringWithFormat:@"0%d",comps.month];
	}
	else {
		month = [NSString stringWithFormat:@"%d",comps.month];
	}
	
	if (comps.day < 10) {
		day = [NSString stringWithFormat:@"0%d",comps.day];
	}
	else {
		day = [NSString stringWithFormat:@"%d",comps.day];
	}
	
	NSString *currentTime = [NSString stringWithFormat:@"%@-%@-%@",year,month,day];
	
	
	result = [stationTime compare:currentTime] == NSOrderedDescending || [currentTime isEqual:stationTime];
}


-(void)getMoreInfo{
	
	Reachability *internetReach = [Reachability reachabilityForInternetConnection];
	[internetReach startNotifier];	
	NetworkStatus netStatus = [internetReach currentReachabilityStatus];
	
	if (netStatus) {
		
		
		NSString *urlString = [NSString stringWithFormat:@"%@?city=%@",kRoadshowCityMore,city];
		
		urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
		
		NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
		NSLog(@"%@",urlString);
		
		DetailWebViewController *detailVC = [[DetailWebViewController alloc] init];
		[detailVC.webView loadRequest:request];
		[rs3VC.navigationController pushViewController:detailVC animated:YES];
		[detailVC release];
	}
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"本功能需要网络支持，请检查网络连接！"
													   delegate:nil cancelButtonTitle:@"确定"
											  otherButtonTitles:nil];
		[alert show];
		[alert release];		
	}
	
}



- (void)keyboardBack{
	[nameField resignFirstResponder];
	[phoneField resignFirstResponder];

	
}

//我要参加
- (void)IWantJoin{

//	[rs3VC.segmentControl setUserInteractionEnabled:NO];
//	[rs3VC.scrollView setScrollEnabled:NO];
//	
//	appDelegate = (SmartRoadShowAppDelegate *)[[UIApplication sharedApplication] delegate];
//	[appDelegate.tabBarController.tabBar setUserInteractionEnabled:NO];
//	
//	[rs3VC.navigationController.navigationBar setUserInteractionEnabled:NO];
	
	joinView = [[UIView alloc] initWithFrame:CGRectMake(5, 40, 310, 304)];
	[joinView setTag:311];
	[joinView setBackgroundColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.9]];
	joinView.layer.cornerRadius = 10;
	joinView.layer.masksToBounds =	YES;
	[rs3VC.view addSubview:joinView];
	[joinView release];
	
	UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, 310, 304)];
	[control addTarget:self action:@selector(keyboardBack) forControlEvents:UIControlEventTouchUpInside];
	[joinView addSubview:control];
	[control release];
	
	
	UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 260, 30)];
	[titleLabel setText:@"预约参加smart都市新主张"];
	[titleLabel setBackgroundColor:[UIColor clearColor]];
	[titleLabel setTextColor:[UIColor colorWithRed:0.97 green:0.80 blue:0.20 alpha:1]];
	[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
	[titleLabel setTextAlignment:UITextAlignmentCenter];
	[joinView addSubview:titleLabel];
	[titleLabel release];
	
	UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 50, 300, 35)];
	[descriptionLabel setText:@"畅游都市新节奏，熠动都市新主张。快来参加“2010 smart 都市新主张”巡展活动！"];
	[descriptionLabel setNumberOfLines:2];
	[descriptionLabel setFont:[UIFont boldSystemFontOfSize:13.5]];
	[descriptionLabel setBackgroundColor:[UIColor clearColor]];
	[descriptionLabel setTextColor:[UIColor whiteColor]];
	[joinView addSubview:descriptionLabel];
	[descriptionLabel release];
	
	UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 90, 60, 30)];
	[nameLabel setText:@"   姓名"];
	[nameLabel setBackgroundColor:[UIColor clearColor]];
	[nameLabel setTextColor:[UIColor colorWithRed:0.97 green:0.80 blue:0.20 alpha:1]];
	[nameLabel setFont:[UIFont boldSystemFontOfSize:16]];
	[joinView addSubview:nameLabel];
	[nameLabel release];
	
	nameField = [[UITextField alloc] initWithFrame:CGRectMake(80, 90, 210, 25)];
	[nameField setBorderStyle:UITextBorderStyleRoundedRect];
	[nameField setDelegate:self];
	[joinView addSubview:nameField];
	[nameField release];
	
	UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 120, 60, 30)];
	[phoneLabel setText:@"   手机"];
	[phoneLabel setBackgroundColor:[UIColor clearColor]];
	[phoneLabel setTextColor:[UIColor colorWithRed:0.97 green:0.80 blue:0.20 alpha:1]];
	[phoneLabel setFont:[UIFont boldSystemFontOfSize:16]];
	[joinView addSubview:phoneLabel];
	[phoneLabel release];
	
	phoneField = [[UITextField alloc] initWithFrame:CGRectMake(80, 120, 210, 25)];
	[phoneField setBorderStyle:UITextBorderStyleRoundedRect];
	[phoneField setKeyboardType:UIKeyboardTypeNumberPad];
	[phoneField setDelegate:self];
	[joinView addSubview:phoneField];
	[phoneField release];
	
	UILabel *stationLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 150, 60, 30)];
	[stationLabel setText:@"参加站"];
	[stationLabel setBackgroundColor:[UIColor clearColor]];
	[stationLabel setTextColor:[UIColor colorWithRed:0.97 green:0.80 blue:0.20 alpha:1]];
	[stationLabel setFont:[UIFont boldSystemFontOfSize:16]];
	[joinView addSubview:stationLabel];
	[stationLabel release];
	
	UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
	[cancel addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
	[cancel setTitle:@"取消" forState:UIControlStateNormal];
	cancel.layer.cornerRadius = 5;
	cancel.layer.masksToBounds =YES;
	[cancel.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
	[cancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[cancel setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
	[cancel setFrame:CGRectMake(170, 200, 100, 30)];
	[joinView addSubview:cancel];
	
	
	UIButton *bookToJoin = [UIButton buttonWithType:UIButtonTypeCustom];
	[bookToJoin addTarget:self action:@selector(bookToJoin) forControlEvents:UIControlEventTouchUpInside];
	[bookToJoin setTitle:@"预约参加" forState:UIControlStateNormal];
	[bookToJoin.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
	[bookToJoin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[bookToJoin setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
	[bookToJoin setFrame:CGRectMake(40, 200, 100, 30)];
	[joinView addSubview:bookToJoin];
	
	stationButton = [UIButton buttonWithType:UIButtonTypeCustom];
	[stationButton setFrame:CGRectMake(80, 150, 210, 30)];
	[stationButton addTarget:self action:@selector(selectStation) forControlEvents:UIControlEventTouchUpInside];
	[stationButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
	[stationButton setBackgroundImage:[UIImage imageNamed:@"selectCity.png"] forState:UIControlStateNormal];
	[stationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	[stationButton.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
	[stationButton setTitle:[NSString stringWithFormat:@" %@站%@至%@",[[stationArr objectAtIndex:tag] _city],[[stationArr objectAtIndex:tag] _starttime],[[stationArr objectAtIndex:tag] _endtime]] forState:UIControlStateNormal];
	[joinView addSubview:stationButton];
	selectedCity = [[stationArr objectAtIndex:tag] _city];
	
	UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(20, 255, 150, 30)];
	[line setText:@"smart客服热线"];
	[line setBackgroundColor:[UIColor clearColor]];
	[line setTextColor:[UIColor colorWithRed:0.97 green:0.80 blue:0.20 alpha:1]];
	[line setFont:[UIFont boldSystemFontOfSize:13.5]];
	[joinView addSubview:line];
	[line release];
	
	UIButton *callButton = [UIButton buttonWithType:UIButtonTypeCustom];
	[callButton addTarget:self action:@selector(callHotline) forControlEvents:UIControlEventTouchUpInside];
	[callButton setFrame:CGRectMake(240, 260, 20, 20)];
	[callButton setImage:[UIImage imageNamed:@"call.png"] forState:UIControlStateNormal];
	[joinView addSubview:callButton];
	
	
	UILabel *number = [[UILabel alloc] initWithFrame:CGRectMake(120, 255, 150, 30)];
	[number setText:@"400- 811- 0000"];
	[number setBackgroundColor:[UIColor clearColor]];
	[number setTextColor:[UIColor whiteColor]];
	[number setFont:[UIFont boldSystemFontOfSize:15.5]];
	[joinView addSubview:number];
	[number release];
	
	myTableView = [[UITableView alloc] initWithFrame:CGRectMake(80, 178, 200, 110) style:UITableViewStylePlain];
	myTableView.layer.cornerRadius = 5;
	myTableView.layer.masksToBounds = YES;
	[myTableView setDelegate:self];
	[myTableView setDataSource:self];
	[myTableView setBackgroundColor:[UIColor colorWithRed:0.953 green:0.922 blue:0.741 alpha:1]];
	[myTableView setSeparatorColor:[UIColor lightGrayColor]];
	flag = YES;
	
	
	
	
}



-(void)callHotline{
	CallUtil *call = [CallUtil getInstance];
	[call callPhoneNumber:@"400- 811- 0000"];
}

-(void)bookToJoin{
	
	Reachability *internetReach = [Reachability reachabilityForInternetConnection];
	[internetReach startNotifier];	
	NetworkStatus netStatus = [internetReach currentReachabilityStatus];
	
	if (netStatus) {
		
		
		if ([[nameField text] length] != 0 && [[phoneField text] length] != 0) {
			
			
			NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:kBookToJoin]];
			[request setHTTPMethod:@"POST"];
			
			NSString *postStr = [NSString stringWithFormat:@"action=reg&infotype=2&username=%@&telphone=%@&city=%@&from=iphone",nameField.text,phoneField.text,selectedCity];
			
			NSData *postData = [postStr dataUsingEncoding:NSUTF8StringEncoding];
			NSString *postDataLength = [NSString stringWithFormat:@"%d",[postData length]];
			
			[request setHTTPBody:postData];
			
			[request setValue: postDataLength forHTTPHeaderField:@"Content-Length"];
			
			NSError *error = nil;
			NSURLResponse *response = nil;
			NSData *urlData = [NSURLConnection 
							   sendSynchronousRequest:request 
							   returningResponse: &response 
							   error: &error];
			
			NSString *responseString = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];
			[request release];
			NSLog(@"response : %@",responseString);
			
			
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您的信息已提交，请等待客服人员与您联系。"
															message:@""
														   delegate:self
												  cancelButtonTitle:@"确定"
												  otherButtonTitles:nil];
			[alert setTag:888];
			[alert show];
			[alert release];
			
		}
		else {
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请将信息填写完整后再提交"
															message:@""
														   delegate:nil
												  cancelButtonTitle:@"确定"
												  otherButtonTitles:nil];
			[alert show];
			[alert release];
		}
	}
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"本功能需要网络支持，请检查网络连接！"
													   delegate:nil cancelButtonTitle:@"确定"
											  otherButtonTitles:nil];
		[alert show];
		[alert release];		
	}

	
}


- (void)selectStation{
		
	[nameField resignFirstResponder];
	[phoneField resignFirstResponder];

	
	if (flag) {
		[joinView addSubview:myTableView];
		flag = NO;
	}
	else {
		[myTableView removeFromSuperview];
		flag = YES;
	}
}

#pragma mark UITableView Delegate & DataSource
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
	return self.leftCityCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	static NSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIndentifier] autorelease];
		[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
	}
	NSInteger row = indexPath.row + [stationArr count] - self.leftCityCount;
	[cell.textLabel setFont:[UIFont boldSystemFontOfSize:12]];
	cell.textLabel.text = [NSString stringWithFormat:@"%@站%@至%@",[[stationArr objectAtIndex:row] _city],[[stationArr objectAtIndex:row] _starttime],[[stationArr objectAtIndex:row] _endtime]];
    
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	
	NSInteger row = indexPath.row + [stationArr count] - self.leftCityCount;
	selectedCity = [[stationArr objectAtIndex:row] _city];
	[stationButton setTitle:[NSString stringWithFormat:@" %@站%@至%@",[[stationArr objectAtIndex:row] _city],[[stationArr objectAtIndex:row] _starttime],[[stationArr objectAtIndex:row] _endtime]]
				   forState:UIControlStateNormal];
	[tableView removeFromSuperview];
	flag = YES;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	return 30;
}

#pragma mark UIAlertView delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//	[rs3VC.segmentControl setUserInteractionEnabled:YES];
//	[rs3VC.scrollView setScrollEnabled:YES];
//
//	[appDelegate.tabBarController.tabBar setUserInteractionEnabled:YES];
//	[rs3VC.navigationController.navigationBar setUserInteractionEnabled:YES];
	
	if (alertView.tag == 888) {
		[joinView removeFromSuperview];
	}
	
	if (buttonIndex == 0 && alertView.tag == 666){
		NSString *strUrl = [NSString stringWithFormat:@"%@",[[stationArr objectAtIndex:tag] _mapURL]];
		strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
		NSURL *url = [NSURL URLWithString:strUrl];
		[[UIApplication sharedApplication] openURL:url];

	}
	if(alertView.tag == 889){
		
		
		if(buttonIndex == 0){ //已经关注过的，取消关注，变成灰色
			
			if (buttonState == red) {
				ifConcern = NO;
				[star setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
				buttonState = gary;
				//[PushedCitys deleteWhileCity:city Time:time];
				[PushedCitys deleteById:newsId];
				//------------------------------------
				notiInfo = [[InfoMgr alloc]init];
				UILocalNotification *notification1 = (UILocalNotification *)[notiInfo getDataForKey:newsId];
				[[UIApplication sharedApplication]   cancelLocalNotification:notification1];
				[notiInfo deleteDateForKey:newsId];
				[notiInfo release];
				
//				NSURL* url = [NSURL URLWithString:kCancelSendURL];
//				NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
//				[request setTimeoutInterval:30];
//				[request setHTTPMethod:@"POST"];
//				
//				SmartRoadShowAppDelegate *app = (SmartRoadShowAppDelegate *)[[UIApplication sharedApplication] delegate];
//				NSString *token = app.token;
//								
//				NSString* postStr = [NSString stringWithFormat:@"token=%@&type=1&city=%@&time=%@&sendid=0",token, city, time];
//				NSData* postData = [postStr dataUsingEncoding:NSUTF8StringEncoding];
//				[request setHTTPBody:postData];
//				
//				NSError *error = nil;
//				NSURLResponse *response = nil;
//				NSData *urlData = [NSURLConnection 
//								   sendSynchronousRequest:request 
//								   returningResponse: &response 
//								   error: &error];
//				
//				NSString *responseString = [[[NSString alloc] initWithData:urlData encoding: NSUTF8StringEncoding] autorelease];		
//				[request release];
//				NSLog(@"%s,%d,respone: %@",__FUNCTION__, __LINE__, responseString);
			}
			
			else if (buttonState == gary) { //没有关注过的，关注一下，变成红色

				ifConcern = YES;
				[star setImage:[UIImage imageNamed:@"star_red.png"] forState:UIControlStateNormal];
				buttonState = red;
				[PushedCitys insertPushedCityWithId:newsId City:city Time:time Title:@""];
				
//				NSString *url_string = kSendURL;	
//				NSURL *url= [NSURL URLWithString:url_string];
//				NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
//				[request setTimeoutInterval: 30];
//				[request setHTTPMethod:@"POST"];
//				SmartRoadShowAppDelegate *app = (SmartRoadShowAppDelegate *)[[UIApplication sharedApplication] delegate];
//				NSString *token = app.token;
//				
//				NSString* postStr = [NSString stringWithFormat:@"token=%@&type=1&city=%@&time=%@&sendid=1",token, city, time];
//				NSData* postData = [postStr dataUsingEncoding:NSUTF8StringEncoding];
//				[request setHTTPBody:postData];
//				
//				NSError *error = nil;
//				NSURLResponse *response = nil;
//				NSData *urlData = [NSURLConnection 
//								   sendSynchronousRequest:request 
//								   returningResponse: &response 
//								   error: &error];
//				
//				NSString *responseString = [[[NSString alloc] initWithData:urlData encoding: NSUTF8StringEncoding] autorelease];		
//				[request release];
//				NSLog(@"%s,%d,respone: %@",__FUNCTION__, __LINE__, responseString);
				
				
				NSString *myDateString = [NSString stringWithFormat:@"%@8:00:00",notiTime];
				NSDateFormatter *inputFormat = [[[NSDateFormatter alloc] init] autorelease];
				[inputFormat setDateFormat:@"yyyy年MM月dd日HH:mm:ss"];
				[inputFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
				NSDate *theDate  = [inputFormat dateFromString:myDateString];
				
				UILocalNotification *notification1=[[UILocalNotification alloc] init];
				notification1.fireDate=theDate;
				notification1.timeZone=[NSTimeZone defaultTimeZone];
				notification1.alertBody=[NSString stringWithFormat:@"%@",city];
				notification1.soundName = UILocalNotificationDefaultSoundName;
				
				notiInfo = [[InfoMgr alloc]init];
				[notiInfo saveData:notification1 forKey:newsId];
				[notiInfo release];
				
				[[UIApplication sharedApplication]   scheduleLocalNotification:notification1];
				
				[notification1 release];
				
				
				
			}
		}
	}
}




- (void)dealloc {
    [super dealloc];
//	[imageView release];
	[placeLabel release];
	[timeLabel release];
	
	[nameField release];
	[phoneField release];
	[selectedCity release];
	
	[stationArr release];
	[joinView release];
	
	[myTableView release];
	[newsId release];
	[city release];
	[time release];
	
//	[star release];
	[leftCityArr release];
	
	[downloadWait release];
	
	
}


@end
